package com.renchunlin.taobaounion.base;

import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.renchunlin.taobaounion.R;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/*
 * class title:
 * Author by RenChunLin, Email 18957806320@163.com, Date on 2021/1/19.
 * PS: Not easy to write code, please indicate.
 */
public abstract class BaseActivity extends AppCompatActivity {

    private Unbinder bind;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());
        //设置灰度
        //SetGrayscale();
        bind = ButterKnife.bind(this);
        initView();
        initEvent();
        initPresenter();
    }

    /**
     * app置灰
     */
    private void SetGrayscale() {
        //=================================
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        Paint paint = new Paint();
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        //View viewById = findViewById(android.R.id.content);
        View contentContainer = getWindow().getDecorView();
        contentContainer.setLayerType(View.LAYER_TYPE_SOFTWARE, paint);
        //=================================
    }

    protected abstract int getLayoutResId();

    protected abstract void initView();

    /**
     * 需要的时候覆写
     */
    protected void initEvent() {

    }

    protected abstract void initPresenter();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (bind != null) {
            bind.unbind();
        }
        this.release();
    }

    /**
     * 子类需要释放资源，覆盖即可
     */
    protected void release() {

    }
}
